package com.wnhoo.smartfishtank.util;

/**
 * Created by Administrator on 2016/5/27.
 */

import android.app.Dialog;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup.LayoutParams;
import android.widget.AdapterView;
import android.widget.EditText;
import android.widget.GridView;
import android.widget.TextView;

import com.wnhoo.smartfishtank.R;
import com.wnhoo.smartfishtank.contants.adapter.ImageAdapter;


public class CustomDialog extends Dialog {
    private EditText editText;
    private TextView sureButton, cancelButton;
    private TextView title;
    private GridView gridview;
    private Context context;
    private ImageAdapter imageAdapter;

    public ImageAdapter getImageAdapter() {
        return imageAdapter;
    }

    public void setImageAdapter(ImageAdapter imageAdapter) {
        this.imageAdapter = imageAdapter;
    }

    public CustomDialog(Context context, int layout) {
        super(context, R.style.dialog);
        this.context = context;
        setCustomDialog(layout);
    }

    private void setCustomDialog(int layout) {
        View mView = LayoutInflater.from(getContext()).inflate(R.layout.color_select, null);
        gridview = (GridView) mView.findViewById(R.id.gridview);
        imageAdapter = new ImageAdapter(context);
        gridview.setAdapter(imageAdapter);//调用ImageAdapter.java
//        gridview.setOnItemClickListener(new AdapterView.OnItemClickListener() {//监听事件
//            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
//                //点击的时候通知adapter选中
////                lastPosition = position;
////                imageAdapter.setSeclection(position);
////                imageAdapter.notifyDataSetChanged();
//                Log.i(".getApplicationContext()", "position" + position);
//                int color = imageAdapter.getColor()[position];
//            }
//        });
        super.setContentView(mView);
    }

    public View getEditText(){
        return editText;
    }

    @Override
    public void setContentView(int layoutResID) {
    }

    @Override
    public void setContentView(View view, LayoutParams params) {
    }

    @Override
    public void setContentView(View view) {
    }

    /**
     * 确定键监听器
     * @param listener
     */
    public void setOnPositiveListener(View.OnClickListener listener){
        sureButton.setOnClickListener(listener);
    }
    public void setOnClickItem(AdapterView.OnItemClickListener listener){
        gridview.setOnItemClickListener(listener);
    }
    /**
     * 取消键监听器
     * @param listener
     */
    public void setOnNegativeListener(View.OnClickListener listener){
        cancelButton.setOnClickListener(listener);
    }
}
